package com.kaiyiweitong.tongxing.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kaiyiweitong.tongxing.R;
import com.kaiyiweitong.tongxing.util.CommonUtil;

/**
 * Created by Administrator on 2017/12/20 0020.
 */

public class ServiceEvaluateAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private final LayoutInflater mInflater;

    public ServiceEvaluateAdapter(Context context) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_service_evaluate, null);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder viewHolder = (MyViewHolder) holder;
        for (int i = 0; i < 5; i++) {
            ImageView star = new ImageView(mContext);
            star.setImageResource(R.mipmap.red_star);
            viewHolder.ll_stars.addView(star);
        }

        for (int i = 0; i < 3; i++) {
            ImageView pic = new ImageView(mContext);

            int width = (CommonUtil.getScreenWidth(mContext) - CommonUtil.dip2px(mContext, 36)) / 3;
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, width);
            if (i != 0) {
                layoutParams.leftMargin = CommonUtil.dip2px(mContext, 7);
            }
            pic.setLayoutParams(layoutParams);

            pic.setImageResource(R.mipmap.star);
            viewHolder.ll_pics.addView(pic);
        }

    }

    @Override
    public int getItemCount() {
        return 5;
    }

    private class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView icon;
        private TextView name;
        private TextView date;
        private LinearLayout ll_stars;
        private LinearLayout ll_pics;
        private TextView content;
        private TextView evaluate;

        public MyViewHolder(View itemView) {
            super(itemView);
            icon = (ImageView) itemView.findViewById(R.id.icon);
            name = (TextView) itemView.findViewById(R.id.name);
            date = (TextView) itemView.findViewById(R.id.date);
            ll_stars = (LinearLayout) itemView.findViewById(R.id.ll_stars);
            ll_pics = (LinearLayout) itemView.findViewById(R.id.ll_pics);
            content = (TextView) itemView.findViewById(R.id.content);
            evaluate = (TextView) itemView.findViewById(R.id.evaluate);
        }
    }
}
